//
//  SMAFNetworkResponse.m
//  Uhou_Framework
//
//  Created by Sunny on 16/1/22.
//  Copyright © 2016年 Sunny. All rights reserved.
//

#import "SMAFNetworkResponse.h"
#import "JSONKit.h"

@implementation SMAFNetworkResponse

/**
 *  返回的结果字符串
 */
- (NSString *)resultString {

    if (self.resultDic) {
        return [self.resultDic JSONString];
    }else {
        return @"";
    }
}
/**
 *  判断是不是成功
 */
- (BOOL)isSuccess {
    
    if ([self.resultDic isKindOfClass:[NSDictionary class]]) {
        
        switch ([self.resultCode integerValue]) {
            case 200:
            {
                return YES;
            }
                break;
            case 300:
            {
                self.errorCode =  [NSString stringWithFormat:@"%@",self.resultDic[@"error_msg"][@"errorCode"]];
                
                switch ([self.errorCode integerValue]) {
                    case 3000001:
                    {
                        self.errorMessage = @"您的帐号在其他设备登录";
                        //                UserLoginViewController *loginVC = [[UserLoginViewController alloc] init];
                        //                [[UIApplication sharedApplication].delegate window].rootViewController = loginVC;
                        //                [TabBarViewController shareTabBarViewController].selectedIndex = 0;
                    } break;
                    case 3000002:
                    {
                        self.errorMessage = @"密码失效，请重新登录";
                        //                UserLoginViewController *loginVC = [[UserLoginViewController alloc] init];
                        //                [[UIApplication sharedApplication].delegate window].rootViewController = loginVC;
                        //                [TabBarViewController shareTabBarViewController].selectedIndex = 0;
                    } break;
                    case 3000003:
                    {
                        self.errorMessage = @"密码错误，请重新输入";
                    } break;
                    case 3000004:
                    {
                        self.errorMessage = @"验证码错误，请重新输入";
                    } break;
                    case 3000005:
                    {
                        self.errorMessage = @"通关密语无效";
                    } break;
                    case 3001001:
                        self.errorMessage = @"加群失败";
                        break;
                        
                    case 3001002:
                        self.errorMessage = @"未找到申请信息";
                        break;
                    case 3001003:
                        self.errorMessage = @"您好像不是群主，没有权限";
                        break;
                    case 3001004:
                        self.errorMessage = @"环信踢人失败";
                        break;
                    case 3001005:
                        self.errorMessage = @"踢人失败";
                        break;
                    case 3001006:
                        self.errorMessage = @"您好像不在这个群";
                        break;
                    case 3001007:
                        self.errorMessage = @"解散群失败";
                        break;
                    case 3001008:
                        self.errorMessage = @"环信退出群失败";
                        break;
                    case 3001009:
                        self.errorMessage = @"退出群失败";
                        break;
                    case 3001010:
                        self.errorMessage = @"更新群信息失败";
                        break;
                    case 3001011:
                        self.errorMessage = @"群不存在";
                        break;
                    case 3001012:
                        self.errorMessage = @"邀请加群失败";
                        break;
                    case 3001013:
                        self.errorMessage = @"还没有达到活动要求哦~";
                        break;
                    case 3001014:
                        self.errorMessage = @"删除群申请失败";
                        break;
                    case 3001015:
                        self.errorMessage = @"转让群主失败";
                        break;
                    case 3001016:
                        self.errorMessage = @"还没到活动时间哦~";
                        break;
                    case 3002001:
                        self.errorMessage = @"好友不存在";
                        break;
                    case 3002002:
                        self.errorMessage = @"删除好友失败";
                        break;
                    case 3002003:
                        self.errorMessage = @"环信添加好友失败";
                        break;
                    case 3002004:
                        self.errorMessage = @"添加好友失败";
                        break;
                    case 3002005:
                        self.errorMessage = @"删除好友申请失败";
                        break;
                    case 3003001:
                        self.errorMessage = @"用户不存在";
                        break;
                    case 3003002:
                        self.errorMessage = @"手机号已存在";
                        break;
                    case 3003003:
                        self.errorMessage = @"Uhou号已存在";
                        break;
                    case 3003004:
                        self.errorMessage = @"Uhou号格式错误";
                        break;
                    case 3003005:
                        self.errorMessage = @"环信注册失败";
                        break;
                    case 3003006:
                        self.errorMessage = @"用户信息更新失败";
                        break;
                    case 3004001:
                        self.errorMessage = @"账户信息更新失败";
                        break;
                    case 3005001:
                        self.errorMessage = @"红包生成失败";
                        break;
                    case 3005002:
                        self.errorMessage = @"抢红包失败";
                        break;
                    case 3006001:
                        self.errorMessage = @"文件上传失败";
                        break;
                    default:
                        self.errorMessage = @"请求失败";
                        break;
                }
                [MBProgressHUD showActiveMessage:self.errorMessage withBackground:NO];
                
                return NO;
            }
                break;
            default:
            {
                [MBProgressHUD showActiveMessage:self.errorMessage withBackground:NO];
                return NO;
            }
                break;
        }
        
    }else {
        return NO;
    }
}

/**
 *  工厂模式获取类实例
 *
 *  @return
 */

+ (SMAFNetworkResponse *)getResponse {

    return [SMAFNetworkResponse new];
}

@end
